package cn.amebius.avoice.service.impl;

import cn.amebius.avoice.mapper.StudentMapper;
import cn.amebius.avoice.pojo.users.Student;
import cn.amebius.avoice.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 阿伟
 * @Date 2022/10/15 17:46
 */
@Service
public class StudentServiceImpl implements StudentService {

    /**
     * 自动填装studentMapper相当于Dao的操作。
     */
    @Autowired
    private StudentMapper studentMapper;

    /**
     * @param student student实体类
     * @return 登录是否成功
     */
    @Override
    public boolean studentLogin(Student student) {
        Student retStudent = studentMapper.getStudentByStudentNumber(student.getStudentNumber());
        if (retStudent != null  && retStudent.getPassword().equals(student.getPassword())) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param student 传入用户实体类（包含studentNumber）
     * @return true 存在 false 不存在
     */
    @Override
    public boolean studentExist(Student student) {
        Student retStudent = studentMapper.getStudentByStudentNumber(student.getStudentNumber());
        if (retStudent == null) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * @param student 传入用户实体类（包含studentNumber）
     * @return true 存在 false 不存在
     */
    @Override
    public boolean studentRegister(Student student) {
        return studentMapper.insertStudent(student);
    }

    /**
     * @param student 传入用户实体类(包含studentNumber和password)
     * @return 修改是否成功
     */
    @Override
    public boolean studentForget(Student student) {
        return studentMapper.updateStudentPasswordByStudentNumber(student.getStudentNumber(),student.getPassword());
    }


}
